function [stack]=apply_monomial_filters(fimg,fb)
% function [stack]=apply_monomial_filters(fimg,fb)
% INPUTS:
%   fimg- a M*N*2 matrix containing the vector field
%   fb- filter bank structure;
% OUTPUTS:
%   stack- a stack of M*N responses
[M,N,nc]=size(fimg);
if(nc~=2)
    error('fimg must be 2 channel 2-D matrix');
end
nstack=round(size(fb,4));
stack=zeros(M,N,nstack);
for ii=1:nstack
    stack(:,:,ii)=complex_conv2(fimg,fb(:,:,:,ii));
end
end

function [rsp]=complex_conv2(fimg,ff)
%    rsp=zeros(size(fimg));
    rsp=abs(filter2(ff(:,:,1),fimg(:,:,1),'same')) + abs(filter2(ff(:,:,2),fimg(:,:,2),'same'));
%     rsp = normxcorr2(ff(:,:,1),fimg(:,:,1)) + normxcorr2(ff(:,:,2),fimg(:,:,2));
%     rsp = imresize(rsp,[size(fimg,1) size(fimg,2)],'bicubic');
    %rsp=max(abs(xcorr(ff(:,:,1),fimg(:,:,1),'coeff')))+max(abs(xcorr(ff(:,:,2),fimg(:,:,2),'coeff')));
    %rsp = abs(rsp);  %add absolute value
    %% CUDA code, not implemented for the moment
    
end
